package com.ajie.ft_kvdata;



import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.Iterator;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sp = this.getSharedPreferences("kvdata", Context.MODE_PRIVATE);


//        KvDataApplication.getInstance().changeSPLocation();
    }

    int count = 0;
    public void putSp( View view) {
        KvDataApplication.getInstance().changeSPLocation();
        SharedPreferences.Editor editor = sp.edit().putString((count++) + "key",   count + " value");
        editor.commit();
    }


    public void spForEach(View view) {
        KvDataApplication.getInstance().changeSPLocation();
        Map<String, ?> map = sp.getAll();
        Iterator<? extends Map.Entry<String, ?>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<String, ?> entry = iterator.next();
            Log.i(TAG, "spForEach: k:"+entry.getKey()+"  v:"+entry.getValue());
        }

    }
}